﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "ui_NewInPlaceFamDlg.h"
#include "UIGeneralDialog.h"

#include "UniIdentity.h"

namespace gcmp
{
    class IDocument;
    class ElementId;
}

class NewInPlaceFamDlgExchangeData : public IGeneralDialogExchangeData
{
public:
    NewInPlaceFamDlgExchangeData();
    virtual void SaveToString(std::wstring* pStr) override;
    virtual void LoadFromString(const std::wstring& str) override;

public:
    std::wstring FamName;
    gcmp::UniIdentity CategoryUid;
    std::wstring WorkingLevelName;
    gcmp::ElementId WorkLevelId;
};

class NewInPlaceFamDlg : public QDialog
{
    Q_OBJECT
public:
    // 新建构件
    explicit NewInPlaceFamDlg(const gcmp::IDocument* pDoc, const gcmp::ElementId currentLevelId, QWidget * pParent = nullptr);

    // 放置构件
    explicit NewInPlaceFamDlg(const gcmp::IDocument* pDoc, const std::set<gcmp::UniIdentity> & instantiatedCategoryUids, const gcmp::ElementId currentLevelId, QWidget * pParent = nullptr);

    const NewInPlaceFamDlgExchangeData& GetExchangeData() const { return m_exchangeData; }

private:
    void Init(const gcmp::IDocument* pDoc, const std::set<gcmp::UniIdentity>& availableCategoryUids, const gcmp::ElementId currentLevelId);

private slots:
    void OnOkButtonPressed();
    void OnCancelButtonPressed();
    void OnCategoryCellClicked(int row, int column);

private:
    Ui::NewInPlaceFamDlg ui;
    NewInPlaceFamDlgExchangeData m_exchangeData;
    int m_categoryTableColumnCount;

    const static int s_categoryTableColumnCount  = 2;
    const static int s_categoryTableColumnHeight = 64;
    const static int s_categoryTableIconSize     = 64;
};
